package com.iwinding.ladygg.modle.db;

import android.content.Context;

import com.iwinding.ladygg.constant.Constant;
import com.iwinding.ladygg.modle.db.bean.Login;
import com.iwinding.ladygg.modle.db.bean.Users;
import com.iwinding.ladygg.modle.db.dao.DaoMaster;
import com.iwinding.ladygg.modle.db.dao.DaoSession;

import java.util.List;


/**
 * Created by Administrator on 2016/6/2.
 */
public class DBHelper {

    private static DaoMaster master;
    private static DaoSession session;

    public static void initDB(Context context){
        if(master==null){
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, Constant.DBConstant.DBNAME,null);
            master = new DaoMaster(helper.getReadableDatabase());
        }
        if(session==null){
            session = master.newSession();
        }
    }

    public static DaoSession getSession(Context context){
        if(session==null){
            initDB(context);
        }
        return session;
    }


    public interface ILoginHelper{
        void updateOrInsertAccount(Login user);
        Login queryLastAccount();
    }

    public interface IUserHelper{
        Users queryUserByGroupId(String groupId);
        List<Users> queryUsers();
        void addAllUsers(List<Users> userses);
    }

}
